import React, { Component } from "react";
import { View, Text, TextInput, Alert } from "react-native";
import CustomHeader from "../../components/CustomHeader";
import { ListItem, Input } from "react-native-elements";
import { request } from "../../utils";

class Feedback extends Component {
  constructor(props) {
    super(props);
    this.state = {
      联系方式: "",
      反馈内容: ""
    };
  }

  提交 = _ => {
    const { 联系方式, 反馈内容 } = this.state;
    const { navigation } = this.props;

    request(
      "feedback/add",
      { Contact: 联系方式, Content: 反馈内容 },
      _ => {
        Alert.alert("反馈成功,谢谢", "", [
          { text: "确定", onPress: _ => navigation.goBack() }
        ]);
      },
      data => {
        Alert.alert("反馈失败", data, [{ text: "确定" }]);
      }
    );
  };
  render() {
    return (
      <View>
        <CustomHeader title="意见反馈" right="check" onRightClick={this.提交} />
        <Input
          onChangeText={反馈内容 => this.setState({ 反馈内容 })}
          placeholder="反馈内容(必填)"
          multiline={true}
        />
        <Input
          onChangeText={联系方式 => this.setState({ 联系方式 })}
          placeholder="联系方式(选填)"
        />
      </View>
    );
  }
}

export default Feedback;
